<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FMCW雷达波形参数计算器</title>
    <!-- 引入MathJax库 -->
    <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        :root {
            --primary: #165DFF;
            --primary-light: #E8F3FF;
            --primary-dark: #0E42CC;
            --gray-50: #F9FAFB;
            --gray-100: #F3F4F6;
            --gray-200: #E5E7EB;
            --gray-300: #D1D5DB;
            --gray-500: #6B7280;
            --gray-700: #374151;
            --gray-800: #1F2937;
            --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
            --transition: all 0.2s ease;
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
        }
        
        body {
            padding: 20px;
            background-color: var(--gray-50);
            color: var(--gray-800);
            line-height: 1.6;
            font-size: 14px;
        }
        
        header {
            width: 100%;
            margin-bottom: 24px;
            text-align: center;
            padding: 10px 0 20px;
            border-bottom: 1px solid var(--gray-200);
        }
        
        .main-title {
            color: var(--primary-dark);
            font-weight: 700;
            font-size: 2.2rem;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
        }
        
        .sub-title {
            color: var(--gray-500);
            font-size: 1rem;
            font-weight: 400;
            max-width: 800px;
            margin: 0 auto;
        }
        
        .container {
            display: flex;
            flex-wrap: wrap;
            gap: 24px;
            width: 100%;
            max-width: 1600px;
            margin: 0 auto;
        }
        
        .left-panel {
            flex: 1;
            min-width: 350px;
            display: flex;
            flex-direction: column;
            gap: 24px;
        }
        
        .card {
            background: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            overflow: hidden;
            transition: var(--transition);
        }
        
        .card:hover {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }
        
        .card-header {
            padding: 16px 20px;
            border-bottom: 1px solid var(--gray-200);
            background-color: var(--primary-light);
        }
        
        .card-header h2 {
            font-size: 1.25rem;
            color: var(--primary-dark);
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .card-body {
            padding: 20px;
        }
        
        .pulse-diagram img {
            width: 100%;
            height: auto;
            border-radius: 8px;
        }
        
        .input-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
            margin-top: 16px;
        }
        
        .input-item {
            display: flex;
            flex-direction: column;
            gap: 6px;
        }
        
        .input-item label {
            font-weight: 500;
            color: var(--gray-700);
            font-size: 14px;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        
        .input-item input {
            padding: 10px 14px;
            border: 1px solid var(--gray-200);
            border-radius: 6px;
            font-size: 14px;
            transition: var(--transition);
        }
        
        .input-item input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
        }
        
        .right-panel {
            flex: 1.5;
            min-width: 350px;
        }
        
        .result-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }
        
        .result-header h2 {
            color: var(--primary-dark);
            font-weight: 600;
            font-size: 1.25rem;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .export-buttons {
            display: flex;
            gap: 12px;
        }
        
        .export-btn {
            padding: 10px 18px;
            border: none;
            border-radius: 6px;
            background-color: var(--primary);
            color: white;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: var(--transition);
        }
        
        .export-btn:hover {
            background-color: var(--primary-dark);
        }
        
        /* 列表式结果展示区域 */
        .results-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        
        .result-item {
            display: grid;
            grid-template-columns: 1fr 2fr 1.2fr;
            gap: 16px;
            padding: 14px 16px;
            background-color: white;
            border-radius: 8px;
            border-left: 4px solid var(--primary);
            box-shadow: var(--shadow);
            transition: var(--transition);
            align-items: center;
        }
        
        .result-item:hover {
            transform: translateX(4px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }
        
        .result-item:nth-child(even) {
            border-left-color: var(--primary-light);
        }
        
        .param-name {
            font-weight: 500;
            color: var(--gray-800);
            font-size: 15px;
        }
        
        .param-formula {
            color: var(--gray-700);
            font-size: 14px;
            line-height: 1.6;
            font-family: 'Noto Sans', sans-serif;
        }
        
        .param-value {
            /* 优化结果字体 - 使用更清晰现代的等宽字体 */
            font-family: 'Consolas', 'Monaco', 'Menlo', 'Roboto Mono', 'Segoe UI Mono', monospace;
            font-weight: 500;
            color: var(--primary-dark);
            font-size: 15px;
            line-height: 1.4;
            text-align: right;
            padding: 8px 12px;
            background-color: var(--primary-light);
            border-radius: 6px;
            letter-spacing: 0.02em;
        }
        
        .warning {
            color: #F53F3F;
            font-size: 13px;
            margin-top: 8px;
            padding: 8px 12px;
            background-color: rgba(245, 63, 63, 0.08);
            border-radius: 4px;
            display: none;
            border-left: 3px solid #F53F3F;
            align-items: center;
            gap: 6px;
        }
        
        @media (max-width: 1024px) {
            .result-item {
                grid-template-columns: 1fr;
                gap: 8px;
            }
            
            .param-value {
                text-align: left;
                font-size: 14px;
            }
        }
        
        @media (max-width: 992px) {
            .container {
                flex-direction: column;
            }
            
            .left-panel, .right-panel {
                width: 100%;
                min-width: auto;
            }
            
            .input-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <header>
        <h1 class="main-title"><i class="fa fa-radar"></i> FMCW雷达波形参数计算器</h1>
        <p class="sub-title">实时计算调频连续波(FMCW)雷达的关键参数，支持自定义输入与动态结果更新</p>
    </header>
    
    <div class="container">
        <div class="left-panel">
            <div class="card pulse-diagram">
                <div class="card-header">
                    <h2><i class="fa fa-line-chart"></i> 单脉冲参数示意图</h2>
                </div>
                <div class="card-body">
                    <img src="https://dev.ti.com/gallery/view/mmwave/mmWaveSensingEstimator/ver/2.5.1/app/chirp_diagram.png" 
                         alt="FMCW脉冲波形图，展示了频率随时间变化的关系">
                </div>
            </div>

            <div class="card input-section">
                <div class="card-header">
                    <h2><i class="fa fa-sliders"></i> 输入参数配置</h2>
                </div>
                <div class="card-body">
                    <div class="input-grid">
                        <div class="input-item">
                            <label for="fc"><i class="fa fa-signal"></i> 中心频率 (GHz)</label>
                            <input type="number" id="fc" value="77" step="0.1" min="1">
                        </div>
                        <div class="input-item">
                            <label for="antennaLambda"><i class="fa fa-arrows-h"></i> 天线间距 (λ倍数)</label>
                            <input type="number" id="antennaLambda" value="0.5" step="0.1" min="0.1">
                        </div>
                        <div class="input-item">
                            <label for="B"><i class="fa fa-broadcast-tower"></i> 调制带宽 (MHz)</label>
                            <input type="number" id="B" value="4000" step="10" min="10">
                        </div>
                        <div class="input-item">
                            <label for="fsIf"><i class="fa fa-wave-square"></i> 中频采样带宽 (MHz)</label>
                            <input type="number" id="fsIf" value="10" step="0.1" min="0.1">
                        </div>
                        <div class="input-item">
                            <label for="rangeFft"><i class="fa fa-th-large"></i> 距离FFT点数</label>
                            <input type="number" id="rangeFft" value="256" step="1" min="16">
                        </div>
                        <div class="input-item">
                            <label for="velFft"><i class="fa fa-tachometer"></i> 速度FFT点数</label>
                            <input type="number" id="velFft" value="128" step="1" min="8">
                        </div>
                        <div class="input-item">
                            <label for="txCount"><i class="fa fa-transmit"></i> Tx发射通道数</label>
                            <input type="number" id="txCount" value="1" step="1" min="1">
                        </div>
                        <div class="input-item">
                            <label for="rxCount"><i class="fa fa-receive"></i> Rx接收通道数</label>
                            <input type="number" id="rxCount" value="4" step="1" min="1">
                        </div>
                        <div class="input-item">
                            <label for="rampEndTime"><i class="fa fa-clock-o"></i> RampEndTime (μs)</label>
                            <input type="number" id="rampEndTime" value="40" step="1" min="1">
                        </div>
                        <div class="input-item">
                            <label for="idleTime"><i class="fa fa-pause"></i> IdleTime (μs)</label>
                            <input type="number" id="idleTime" value="10" step="1" min="0">
                        </div>
                    </div>
                    <div class="warning" id="warning"><i class="fa fa-exclamation-triangle"></i> RampEndTime不能为0，请重新输入！</div>
                </div>
            </div>
        </div>

        <div class="right-panel">
            <div class="card">
                <div class="card-header">
                    <div class="result-header">
                        <h2><i class="fa fa-calculator"></i> 波形参数计算结果</h2>
                        <div class="export-buttons">
                            <button class="export-btn" id="exportCsv"><i class="fa fa-file-excel-o"></i> 导出CSV</button>
                            <button class="export-btn" id="exportTxt"><i class="fa fa-file-text-o"></i> 导出TXT</button>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <!-- 列表式结果展示区域 -->
                    <div class="results-list">
                        <!-- 调制斜率 (Slope) -->
                        <div class="result-item">
                            <div class="param-name">调制斜率 (S)</div>
                            <div class="param-formula">\( S = \frac{B}{T_{ramp}} \)（B：调制带宽，\( T_{ramp} \)：RampEndTime）</div>
                            <div class="param-value" id="slopeResult">0 MHz/μs</div>
                        </div>
                        
                        <!-- 雷达波长 (λ) -->
                        <div class="result-item">
                            <div class="param-name">雷达波长 (λ)</div>
                            <div class="param-formula">\( \lambda = \frac{c}{f_c} \)（c：光速3×10⁸m/s，\( f_c \)：中心频率）</div>
                            <div class="param-value" id="lambdaResult">0 m</div>
                        </div>
                        
                        <!-- 实际天线间距 -->
                        <div class="result-item">
                            <div class="param-name">实际天线间距</div>
                            <div class="param-formula">\( d = \text{天线间距倍数} \times \lambda \)</div>
                            <div class="param-value" id="antennaDistResult">0 m</div>
                        </div>
                        
                        <!-- 脉冲时间 (T_c) -->
                        <div class="result-item">
                            <div class="param-name">脉冲时间 (T<sub>c</sub>)</div>
                            <div class="param-formula">\( T_c = T_{ramp} + T_{idle} \)</div>
                            <div class="param-value" id="pulseTimeResult">0 μs</div>
                        </div>
                        
                        <!-- MIMO通道数 -->
                        <div class="result-item">
                            <div class="param-name">MIMO通道数</div>
                            <div class="param-formula">\( N_{MIMO} = N_{Tx} \times N_{Rx} \)（\( N_{Tx} \)：Tx数，\( N_{Rx} \)：Rx数）</div>
                            <div class="param-value" id="mimoResult">0 通道</div>
                        </div>
                        
                        <!-- 距离分辨率 (d_res) -->
                        <div class="result-item">
                            <div class="param-name">距离分辨率 (d<sub>res</sub>)</div>
                            <div class="param-formula">\( d_{res} = \frac{c}{2B} \)</div>
                            <div class="param-value" id="rangeResResult">0 m</div>
                        </div>
                        
                        <!-- 最大探测距离 (d_max) -->
                        <div class="result-item">
                            <div class="param-name">最大探测距离 (d<sub>max</sub>)</div>
                            <div class="param-formula">\( d_{max} = \frac{F_s \times c}{2S} \)（\( F_s \)：中频采样带宽）</div>
                            <div class="param-value" id="maxRangeResult">0 m</div>
                        </div>
                        
                        <!-- 帧时间 (T_f) -->
                        <div class="result-item">
                            <div class="param-name">帧时间 (T<sub>f</sub>) (MIMO体制)</div>
                            <div class="param-formula">\( T_f = T_c \times N_{velFFT} \times N_{Tx} \)</div>
                            <div class="param-value" id="frameTimeResult">0 ms</div>
                        </div>
                        
                        <!-- 最大速度 (v_max) -->
                        <div class="result-item">
                            <div class="param-name">最大速度 (v<sub>max</sub>)</div>
                            <div class="param-formula">\( v_{max} = \frac{\lambda}{4T_c} \)（单位：m/s）</div>
                            <div class="param-value" id="maxVelResult">0 m/s</div>
                        </div>
                        
                        <!-- 速度分辨率 (v_res) -->
                        <div class="result-item">
                            <div class="param-name">速度分辨率 (v<sub>res</sub>)</div>
                            <div class="param-formula">\( v_{res} = \frac{\lambda}{2T_f} \)（单位：m/s）</div>
                            <div class="param-value" id="velResResult">0 m/s</div>
                        </div>
                        
                        <!-- 角度分辨率 (θ_res) -->
                        <div class="result-item">
                            <div class="param-name">角度分辨率 (θ<sub>res</sub>)</div>
                            <div class="param-formula">\( \theta_{res} = \frac{\lambda}{N_{Rx} \times d} \times \frac{180^\circ}{\pi} \)（θ=0时，单位：°）</div>
                            <div class="param-value" id="angleResResult">0 °</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 配置MathJax
        window.MathJax = {
            tex: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                displayMath: [['$$', '$$']],
                processEscapes: true
            },
            svg: {
                fontCache: 'global',
                scale: 1.05
            }
        };

        // 等待页面加载完成
        document.addEventListener('DOMContentLoaded', function() {
            // 常量定义
            const c = 3e8; // 光速 (m/s)

            // 获取DOM元素
            const inputs = document.querySelectorAll('input');
            const warningEl = document.getElementById('warning');
            
            // 结果元素映射表
            const resultElements = {
                slopeResult: document.getElementById('slopeResult'),
                lambdaResult: document.getElementById('lambdaResult'),
                antennaDistResult: document.getElementById('antennaDistResult'),
                pulseTimeResult: document.getElementById('pulseTimeResult'),
                mimoResult: document.getElementById('mimoResult'),
                rangeResResult: document.getElementById('rangeResResult'),
                maxRangeResult: document.getElementById('maxRangeResult'),
                frameTimeResult: document.getElementById('frameTimeResult'),
                maxVelResult: document.getElementById('maxVelResult'),
                velResResult: document.getElementById('velResResult'),
                angleResResult: document.getElementById('angleResResult')
            };

            // 页面加载后立即执行计算
            calculateParams();
            
            // 确保MathJax加载完成后渲染公式
            function checkMathJax() {
                if (window.MathJax && MathJax.typeset) {
                    try {
                        MathJax.typeset();
                    } catch (e) {
                        console.warn('MathJax渲染延迟，将重试');
                        setTimeout(checkMathJax, 100);
                    }
                } else {
                    // 未加载完成，100ms后重试
                    setTimeout(checkMathJax, 100);
                }
            }
            
            // 启动MathJax检查
            checkMathJax();

            // 输入参数变化时实时计算
            inputs.forEach(input => {
                input.addEventListener('input', function() {
                    calculateParams();
                    checkMathJax();
                });
                
                input.addEventListener('blur', function() {
                    if (this.value <= 0 && this.id !== 'idleTime') {
                        this.value = this.min || 1;
                        calculateParams();
                        checkMathJax();
                    }
                });
            });

            // 计算核心函数
            function calculateParams() {
                try {
                    // 获取输入值并转换单位
                    const fc = parseFloat(document.getElementById('fc').value) * 1e9; // 中心频率 (Hz)
                    const antennaLambda = parseFloat(document.getElementById('antennaLambda').value);
                    const B = parseFloat(document.getElementById('B').value) * 1e6; // 调制带宽 (Hz)
                    const fsIf = parseFloat(document.getElementById('fsIf').value) * 1e6; // 中频采样带宽 (Hz)
                    const velFft = parseInt(document.getElementById('velFft').value);
                    const txCount = parseInt(document.getElementById('txCount').value);
                    const rxCount = parseInt(document.getElementById('rxCount').value);
                    const rampEndTime = parseFloat(document.getElementById('rampEndTime').value) * 1e-6; // RampEndTime (s)
                    const idleTime = parseFloat(document.getElementById('idleTime').value) * 1e-6; // IdleTime (s)

                    // 验证RampEndTime是否为0
                    if (rampEndTime <= 0) {
                        warningEl.style.display = 'flex';
                        clearResults();
                        return;
                    } else {
                        warningEl.style.display = 'none';
                    }

                    // 1. 调制斜率 (Slope)
                    const slope = B / rampEndTime; // Hz/s
                    const slopeMHzus = slope / 1e12; // 转换为MHz/μs
                    updateResult('slopeResult', `${slopeMHzus.toFixed(2)} MHz/μs`);

                    // 2. 雷达波长 (λ)
                    const lambda = c / fc; // m
                    updateResult('lambdaResult', `${lambda.toFixed(6)} m (${(lambda*1e3).toFixed(3)} mm)`);

                    // 3. 实际天线间距
                    const antennaDist = antennaLambda * lambda; // m
                    updateResult('antennaDistResult', `${antennaDist.toFixed(6)} m (${(antennaDist*1e3).toFixed(3)} mm)`);

                    // 4. 脉冲时间 (T_c)
                    const pulseTime = rampEndTime + idleTime; // s
                    const pulseTimeUs = pulseTime * 1e6; // 转μs显示
                    updateResult('pulseTimeResult', `${pulseTimeUs.toFixed(1)} μs (${pulseTime.toExponential(6)} s)`);

                    // 5. MIMO通道数
                    const mimoCount = txCount * rxCount;
                    updateResult('mimoResult', `${mimoCount} 通道`);

                    // 6. 距离分辨率 (d_res)
                    const rangeRes = c / (2 * B); // m
                    updateResult('rangeResResult', `${rangeRes.toFixed(4)} m (${(rangeRes*1e2).toFixed(2)} cm)`);

                    // 7. 最大探测距离 (d_max)
                    const maxRange = (fsIf * c) / (2 * slope); // m
                    updateResult('maxRangeResult', `${maxRange.toFixed(2)} m (${(maxRange/1e3).toFixed(3)} km)`);

                    // 8. 帧时间 (T_f)
                    const frameTime = pulseTime * velFft * txCount; // s
                    const frameTimeMs = frameTime * 1e3; // 转ms显示
                    updateResult('frameTimeResult', `${frameTimeMs.toFixed(2)} ms (${frameTime.toExponential(6)} s)`);

                    // 9. 最大速度 (v_max)
                    const maxVel = lambda / (4 * pulseTime); // m/s
                    updateResult('maxVelResult', `${maxVel.toFixed(2)} m/s`);

                    // 10. 速度分辨率 (v_res)
                    const velRes = lambda / (2 * frameTime); // m/s
                    updateResult('velResResult', `${velRes.toFixed(4)} m/s`);

                    // 11. 角度分辨率 (θ_res)
                    const angleResRad = lambda / (rxCount * antennaDist);
                    const angleResDeg = angleResRad * (180 / Math.PI); // °
                    updateResult('angleResResult', `${angleResDeg.toFixed(2)} ° (${angleResRad.toExponential(4)} rad)`);

                } catch (error) {
                    console.error('计算过程出错:', error);
                    warningEl.textContent = `计算错误: ${error.message}`;
                    warningEl.style.display = 'flex';
                }
            }

            // 更新结果显示
            function updateResult(elementId, value) {
                const element = resultElements[elementId];
                if (element) {
                    // 添加过渡动画效果
                    element.style.transition = 'all 0.3s ease';
                    element.style.opacity = '0.5';
                    
                    setTimeout(() => {
                        element.textContent = value;
                        element.style.opacity = '1';
                    }, 150);
                }
            }

            // 清空结果
            function clearResults() {
                Object.values(resultElements).forEach(el => {
                    if (el) el.textContent = '-';
                });
            }

            // 导出CSV
            document.getElementById('exportCsv').addEventListener('click', function() {
                const data = [
                    {name: '调制斜率 (S)', value: slopeResult.textContent, formula: 'S = B / T_ramp'},
                    {name: '雷达波长 (λ)', value: lambdaResult.textContent, formula: 'λ = c / f_c'},
                    {name: '实际天线间距', value: antennaDistResult.textContent, formula: 'd = 天线间距倍数 × λ'},
                    {name: '脉冲时间 (T_c)', value: pulseTimeResult.textContent, formula: 'T_c = T_ramp + T_idle'},
                    {name: 'MIMO通道数', value: mimoResult.textContent, formula: 'N_MIMO = N_Tx × N_Rx'},
                    {name: '距离分辨率 (d_res)', value: rangeResResult.textContent, formula: 'd_res = c / (2B)'},
                    {name: '最大探测距离 (d_max)', value: maxRangeResult.textContent, formula: 'd_max = (F_s × c) / (2S)'},
                    {name: '帧时间 (T_f)', value: frameTimeResult.textContent, formula: 'T_f = T_c × N_velFFT × N_Tx'},
                    {name: '最大速度 (v_max)', value: maxVelResult.textContent, formula: 'v_max = λ / (4T_c)'},
                    {name: '速度分辨率 (v_res)', value: velResResult.textContent, formula: 'v_res = λ / (2T_f)'},
                    {name: '角度分辨率 (θ_res)', value: angleResResult.textContent, formula: 'θ_res = λ/(N_Rx×d) × 180°/π'}
                ];
                
                const csvContent = "data:text/csv;charset=utf-8," 
                    + "参数名称,计算公式,计算结果\n" 
                    + data.map(row => `${row.name},${row.formula.replace(/,/g, '，')},${row.value}`).join("\n");
                downloadFile(csvContent, 'FMCW参数计算结果.csv');
            });

            // 导出TXT
            document.getElementById('exportTxt').addEventListener('click', function() {
                const data = [
                    {name: '调制斜率 (S)', value: slopeResult.textContent, formula: 'S = B / T_ramp（B：调制带宽，T_ramp：RampEndTime）'},
                    {name: '雷达波长 (λ)', value: lambdaResult.textContent, formula: 'λ = c / f_c（c：光速3×10⁸m/s，f_c：中心频率）'},
                    {name: '实际天线间距', value: antennaDistResult.textContent, formula: 'd = 天线间距倍数 × λ'},
                    {name: '脉冲时间 (T_c)', value: pulseTimeResult.textContent, formula: 'T_c = T_ramp + T_idle（T_idle：IdleTime）'},
                    {name: 'MIMO通道数', value: mimoResult.textContent, formula: 'N_MIMO = N_Tx × N_Rx（发射×接收通道数）'},
                    {name: '距离分辨率 (d_res)', value: rangeResResult.textContent, formula: 'd_res = c / (2B)'},
                    {name: '最大探测距离 (d_max)', value: maxRangeResult.textContent, formula: 'd_max = (F_s × c) / (2S)（F_s：中频采样带宽）'},
                    {name: '帧时间 (T_f)', value: frameTimeResult.textContent, formula: 'T_f = T_c × N_velFFT × N_Tx'},
                    {name: '最大速度 (v_max)', value: maxVelResult.textContent, formula: 'v_max = λ / (4T_c)'},
                    {name: '速度分辨率 (v_res)', value: velResResult.textContent, formula: 'v_res = λ / (2T_f)'},
                    {name: '角度分辨率 (θ_res)', value: angleResResult.textContent, formula: 'θ_res = λ/(N_Rx×d) × 180°/π（θ=0时）'}
                ];
                
                let txtContent = "FMCW雷达波形参数计算结果\n";
                txtContent += "=".repeat(80) + "\n";
                data.forEach(row => {
                    txtContent += `【${row.name}】\n`;
                    txtContent += `计算公式：${row.formula}\n`;
                    txtContent += `计算结果：${row.value}\n`;
                    txtContent += "-".repeat(80) + "\n";
                });
                const txtBlob = new Blob([txtContent], { type: 'text/plain;charset=utf-8' });
                const url = URL.createObjectURL(txtBlob);
                downloadFile(url, 'FMCW参数计算结果.txt');
            });

            // 下载文件通用函数
            function downloadFile(content, fileName) {
                const link = document.createElement('a');
                link.setAttribute('href', content);
                link.setAttribute('download', fileName);
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
                if (content.startsWith('blob:')) {
                    URL.revokeObjectURL(content);
                }
            }
        });
    </script>
</body>
</html>
    